﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JobSiteStarterKit.DAL;
using JobSiteStarterKit.BOL;
using System.Data.SqlClient;

public partial class jobseeker_myaccounts : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //string username = HttpContext.Current.Session["user"].ToString();
            if (Session["SESS_JobSeekerName"] != null && Convert.ToString(Session["SESS_JobSeekerName"]) != String.Empty)
            {
                string username = Convert.ToString(Session["SESS_JobSeekerName"]);
                using (DBAccess db = new DBAccess())
                {

                    string strprocName = "getuserPassword";
                    db.CommandText = strprocName;
                    db.AddParameter("@Username", username);
                    System.Data.SqlClient.SqlDataReader reader = (System.Data.SqlClient.SqlDataReader)db.ExecuteReader();
                    if (reader.HasRows)
                    {
                        reader.Read();
                        txtOldemail.Text = reader["Password"].ToString();
                    }
                }
            }
            else
            {
                Response.Redirect("login.aspx");
            }
           
        }
        //lblUsername.Text = (string)username;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool id;
    MembershipUser user = Membership.GetUser();
    if (txtnewEmail.Text == "")
    {
        errorpass.InnerHtml = "No New Password Is supplied";
    }
    else
    {
        id = user.ChangePassword(txtOldemail.Text.Trim(), txtnewEmail.Text.Trim());
        //if(id==true)

        changePassword.Visible = false;
    }    
    }
    protected void LnkEditEmail_Click(object sender, EventArgs e)
    {
        changePassword.Visible = true;
        norecord.Visible = false;
        Gridapplied.Visible = false;
    }

    protected void Lnkpostedjobs_Click(object sender, EventArgs e)
    {
        if (Gridapplied.Visible == false)
            Gridapplied.Visible = true;
            getAppliedJobs();  
        
    }
    protected void Gridapplied_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (DataBinder.Eval(e.Row.DataItem, "Status") != null)
        {
            if (DataBinder.Eval(e.Row.DataItem, "Status").ToString() == "1")
            {
                if (e.Row.FindControl("Label1") != null)
                {
                    Label lbl = (Label)e.Row.FindControl("Label1");
                    lbl.Text = "Called";
                }
            }

            else
            {
                if (e.Row.FindControl("Label1") != null)
                {

                    Label lbl = (Label)e.Row.FindControl("Label1");
                    lbl.Text = "In Progress...";
                }
            }
        }
    }
    protected void Gridapplied_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        
        string id = Gridapplied.DataKeys[e.RowIndex].Value.ToString();
        using (DBAccess db = new DBAccess())
        {
            string strprocName = "deleteJobsDetails";
            db.CommandText = strprocName;
            db.AddParameter("@MyJobID", id);
            db.ExecuteNonQuery();
            
        }
        getAppliedJobs();
    }
    public void getAppliedJobs()
    {
        changePassword.Visible = false;
        string username = HttpContext.Current.Session["user"].ToString();
        using (DBAccess db = new DBAccess())
        {

            //db.AddParameter("@Username", username);
            //dsAppjobs = db.ExecuteDataSet("getAppliedJobsDetails");

            string strprocName = "getAppliedJobsDetails";
            db.CommandText = strprocName;
            db.AddParameter("@Username", username);
            System.Data.SqlClient.SqlDataReader reader = (System.Data.SqlClient.SqlDataReader)db.ExecuteReader();
            if (reader.HasRows)
            {
                Gridapplied.DataSource = reader;
                Gridapplied.DataBind();
            }
            else
            {
                norecord.InnerText = "Sorry No Records";
            }

        }
    }
    protected void btnSeedetails_Click(object sender, ImageClickEventArgs e)
    {
        getAppliedJobs();
    }
    protected void btnpassword_Click(object sender, ImageClickEventArgs e)
    {
        changePassword.Visible = true;
    }
}
